#!/bin/sh -x

main() {
 help
 echo "Direct update IPv6 URL to poll: " >&2
 read URL6
 echo "Direct update IPv4 URL to poll (optional): " >&2
 read URL4

 sudo apt-get install -y gogoc
 sudo sed -r -i "s~^(tunnel_mode=).*$~\1v6udpv4~" /etc/gogoc/gogoc.conf

 sudo wget -O /usr/local/bin/v6-afraid.sh http://bkil-open.googlecode.com/svn/trunk/volatile/os/ipv6/v6-afraid.sh
 sudo wget -O /etc/init.d/v6-afraid http://bkil-open.googlecode.com/svn/trunk/volatile/os/ipv6/init/v6-afraid
 sudo chmod +x /usr/local/bin/v6-afraid.sh /etc/init.d/v6-afraid
 cat << EOF |
FORCEUPDATE=600 # minutes
HASH4="$URL4" # can be left empty
HASH6="$URL6" # paste the hash (part after "?") of the IPv6 Direct URL here
EOF
 sudo tee /etc/v6-afraid.conf > /dev/null
 sudo update-rc.d v6-afraid defaults 99
# sudo update-rc.d-insserv v6-afraid defaults 99
# ln -s /etc/init.d/v6-afraid /etc/rc5.d/S99v6-afraid
 sudo service v6-afraid start ||
  cat /var/log/v6-afraid.sh.log
}

help() {
cat <<EOF
There's a simple solution for you if your ISP does not provide IPv6 infrastructure,
you are fed up with NATs, and would rather enjoy direct access for P2P and servers.
Related information: https://wiki.ubuntu.com/IPv6

Please complete these steps manually:
0. install/adjust your firewall and services to prepare for globally routable public access
1. http://freedns.afraid.org/signup/
2. [send activation email]
3. http://freedns.afraid.org/dynamic/
5. [add]: [type] AAAA (IPv6), choose subdomain, destination ::0 (or anything), [save]
6. optional: [type] A (IPv4)
7. http://freedns.afraid.org/dynamic/
8. [Link updates of the same IP together] OFF
9. right click [Direct URL], copy&paste, save each part after "?" (hash)
10. don't forget to sign in to afraid.org once in a few months!
EOF
}

main "$@"
